home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5281 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: po.CWRU.Edu!mab22
  2. From: mab22@po.CWRU.Edu (Michael A. Balfour)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Character String --> Integer
  5. Date: 9 Feb 1996 16:01:18 GMT
  6. Organization: Case Western Reserve University, Cleveland, OH (USA)
  7. Message-ID: <4ffr4e$4ji@madeline.INS.CWRU.Edu>
  8. References: <4fb0ga$lsa@remus.rutgers.edu>
  9. Reply-To: mab22@po.CWRU.Edu (Michael A. Balfour)
  10. NNTP-Posting-Host: kanga.ins.cwru.edu
  11.  
  12.  
  13. In a previous article, wempa@remus.rutgers.edu (Force Of Nature) says:
  14.  
  15. >Is there an easy way to convert a character string such as '2425' to the
  16. >integer 2425 ???  The only way I can think of is to pick off characters 
  17. >one at a time and use switch statements to determine the value (0-9) and
  18. >then multiply by the correct power of 10.  Is there an easier way to do
  19. >this ???????
  20. >
  21. >
  22.  
  23. Just to throw a tiny spin on the discussion, if you don't know if the
  24. character set for the string matches the native character set (i.e.
  25. EBCDIC string on an ASCII machine), you can't use the standard library
  26. functions.  But rather than use a switch statement, you can LOGICAL AND
  27. each character with 0x0F.  It'll save you a little time anyways.
  28.  
  29. Mike Balfour
  30.  
  31. -- 
  32. ----------------------------------+--------------------------------
  33. Mike Balfour, Partner             | BS/MS Candidate - ECMP
  34. Overload Engineering              | Case Western Reserve University
  35. "New Ideas for a Brighter Future" | Cleveland, OH
  36.